﻿using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Serialization;

namespace HeritageAcademy.Models.DataModels
{
    [Serializable]
    [DesignerCategory(@"code")]
    [XmlType(AnonymousType = true)]
    [XmlRoot(Namespace = "", IsNullable = false)]
    public sealed class Settings
    {

        private ObservableCollection<Setting> itemsField = new ObservableCollection<Setting>();

        [XmlElement("Setting", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public ObservableCollection<Setting> Setting
        {
            get
            {
                return itemsField;
            }
            set
            {
                itemsField = value;
            }
        }

        #region Filters

        /// <summary>
        /// Get setting object using its id.
        /// </summary>
        /// <param name="id">Setting object id</param>
        /// <returns>Setting object</returns>
        public Setting GetSettingFromId(string id)
        {
            object setting = null;
            foreach (var t in Setting.Where(t => t.Id == id))
                setting = t;
            return (Setting)setting;
        }

        #endregion
    }

    [Serializable]
    [DesignerCategory(@"code")]
    [XmlType(AnonymousType = true)]
    public sealed class Setting
    {
        private string lineSpacingField;
        private string colorSchemeField;
        private string zoomField;
        private string resizeControlsForTouchField;
        private string lastSelectedViewIsLibraryField;
        private string id;

        /// <remarks/>
        [XmlElement("LineSpacing", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
        public string LineSpacing
        {
            get { return lineSpacingField; }
            set { lineSpacingField = value; }
        }

        /// <remarks/>
        [XmlElement("ColorScheme", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
        public string ColorScheme
        {
            get { return colorSchemeField; }
            set { colorSchemeField = value; }
        }

        /// <remarks/>
        [XmlElement("Zoom", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
        public string Zoom
        {
            get { return zoomField; }
            set { zoomField = value; }
        }

        /// <remarks/>
        [XmlElement("ResizeControlsForTouch", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
        public string ResizeControlsForTouch
        {
            get { return resizeControlsForTouchField; }
            set { resizeControlsForTouchField = value; }
        }

        /// <remarks/>
        [XmlElement("LastSelectedViewIsLibrary", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
        public string LastSelectedViewIsLibrary
        {
            get { return lastSelectedViewIsLibraryField; }
            set { lastSelectedViewIsLibraryField = value; }
        }

        /// <remarks/>
        [XmlAttribute]
        public string Id
        {
            get { return id; }
            set { id = value; }
        }
    }
}
